home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / FWContnt.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  8.5 KB  |  299 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWContnt.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWCONTNT_H
  13. #include "FWContnt.h"
  14. #endif
  15.  
  16. #ifndef FWDEBUG_H
  17. #include "FWDebug.h"
  18. #endif
  19.  
  20. #ifndef FWPRTITE_H
  21. #include "FWPrtIte.h"
  22. #endif
  23.  
  24. #ifndef FWKIND_H
  25. #include "FWKind.h"
  26. #endif
  27.  
  28. #ifndef FWUTIL_H
  29. #include "FWUtil.h"
  30. #endif
  31.  
  32. #ifndef FWPRMISE_H
  33. #include "FWPrmise.h"
  34. #endif
  35.  
  36. #ifndef FWACQUIR_H
  37. #include "FWAcquir.h"
  38. #endif
  39.  
  40. #ifndef FWSUUTIL_H
  41. #include "FWSUUtil.h"
  42. #endif
  43.  
  44. #ifndef FWLNKSRC_H
  45. #include "FWLnkSrc.h"
  46. #endif
  47.  
  48. #ifndef SOM_ODStorageUnit_xh
  49. #include "StorageU.xh"
  50. #endif
  51.  
  52. #ifndef SOM_Module_OpenDoc_StdProps_defined
  53. #include <StdProps.xh>
  54. #endif
  55.  
  56. //========================================================================================
  57. // RunTime Info
  58. //========================================================================================
  59.  
  60. #ifdef FW_BUILD_MAC
  61. #pragma segment FWFrameworkContent
  62. #endif
  63.  
  64. //========================================================================================
  65. //    class FW_CContent
  66. //========================================================================================
  67.  
  68. FW_DEFINE_CLASS_M0(FW_CContent)
  69.  
  70. //----------------------------------------------------------------------------------------
  71. //    FW_CContent constructor
  72. //----------------------------------------------------------------------------------------
  73.  
  74. FW_CContent::FW_CContent(Environment* ev, FW_CPart* part) :
  75.     fPart(part)
  76. {
  77. FW_UNUSED(ev);
  78. }
  79.  
  80. //----------------------------------------------------------------------------------------
  81. //    FW_CContent destructor
  82. //----------------------------------------------------------------------------------------
  83.  
  84. FW_CContent::~FW_CContent()
  85. {
  86. }
  87.  
  88. //----------------------------------------------------------------------------------------
  89. //    FW_CContent::AcquireSuggestedFrameShape
  90. //----------------------------------------------------------------------------------------
  91.  
  92. ODShape* FW_CContent::AcquireSuggestedFrameShape(Environment* ev)
  93. {
  94. FW_UNUSED(ev);
  95.     return NULL;
  96. }
  97.  
  98. //----------------------------------------------------------------------------------------
  99. //    FW_CContent::ReleaseAll
  100. //----------------------------------------------------------------------------------------
  101.  
  102. void FW_CContent::ReleaseAll(Environment* ev)
  103. {
  104. FW_UNUSED(ev);
  105. }
  106.  
  107. //----------------------------------------------------------------------------------------
  108. //    FW_CContent::NewPromise
  109. //----------------------------------------------------------------------------------------
  110.  
  111. FW_CPromise* FW_CContent::NewPromise(Environment* ev, ODStorageUnit* su, FW_StorageKinds storageKind, FW_CCloneInfo* cloneInfo)
  112. {
  113. FW_UNUSED(ev);
  114. FW_UNUSED(su);
  115. FW_UNUSED(storageKind);
  116. FW_UNUSED(cloneInfo);
  117.  
  118.     return NULL;
  119. }
  120.  
  121. //----------------------------------------------------------------------------------------
  122. //    FW_DeletePromiseIfZeroCount
  123. //----------------------------------------------------------------------------------------
  124.  
  125. static void FW_DeletePromiseIfZeroCount(Environment* ev, FW_CPromise* promise)
  126. {
  127.     if (promise && (promise->GetCount(ev) == 0))
  128.     {
  129.         if (promise->GetStorageKind(ev) == FW_kLinkStorage)
  130.             promise->PrivGetLinkSource(ev)->SetLinkPromise(ev, NULL);
  131.         else
  132.             delete promise;
  133.     }
  134. }
  135.  
  136. //----------------------------------------------------------------------------------------
  137. //    FW_CContent::Externalize
  138. //----------------------------------------------------------------------------------------
  139.  
  140. void FW_CContent::Externalize(Environment* ev,
  141.                             ODStorageUnit* storageUnit,
  142.                             FW_StorageKinds storageKind,
  143.                             FW_CCloneInfo* cloneInfo)
  144. {
  145.     FW_CPromise* promise = NULL;
  146.     
  147.     // ----- Try to create a promise ------
  148.     if (storageKind != FW_kPartStorage)    // can't promise for Part storage
  149.         promise = NewPromise(ev, storageUnit, storageKind, cloneInfo);
  150.     
  151.     FW_TRY
  152.     {
  153.         // Go through all the values and externalize them one by one
  154.         this->PrivExternalizeAllValues(ev, storageUnit, storageKind, promise, cloneInfo);
  155.     }
  156.     FW_CATCH_BEGIN
  157.     FW_CATCH_EVERYTHING()
  158.     {
  159.         FW_DeletePromiseIfZeroCount(ev, promise);
  160.         
  161.         FW_THROW_SAME();
  162.     }
  163.     FW_CATCH_END
  164.     
  165.     FW_DeletePromiseIfZeroCount(ev, promise);
  166. }
  167.  
  168. //---------------------------------------------------------------------------------------
  169. //    FW_CContent::PrivExternalizeAllValues
  170. //---------------------------------------------------------------------------------------
  171. //    Private method called from FW_CPart::ExternalizeKinds and FW_CContent::Externalize
  172.  
  173. void FW_CContent::PrivExternalizeAllValues(Environment* ev, 
  174.                                         ODStorageUnit* storageUnit,
  175.                                         FW_StorageKinds storageKind, 
  176.                                         FW_CPromise* promise, 
  177.                                         FW_CCloneInfo* cloneInfo)
  178. {
  179.     // ----- Now I can call FW_CContent::ExternalizeKind on each existing value
  180.     storageUnit->Focus(ev, kODPropContents, kODPosUndefined, NULL, 0, kODPosAll);
  181.     
  182.     unsigned long numValues = storageUnit->CountValues(ev);
  183.     for (unsigned long index = 1; index <= numValues ; index++)
  184.     {
  185.         storageUnit->Focus(ev, kODPropContents, kODPosUndefined, NULL, index, kODPosUndefined);
  186.         FW_CAcquireODISOStr valueType = storageUnit->GetType(ev);
  187.         FW_CKind* kind = fPart->GetKind(ev, valueType);
  188.         
  189.         if (kind && kind->IsDirty(ev, storageKind)) 
  190.         {
  191.             ExternalizeKind(ev, storageUnit, kind, storageKind, promise, cloneInfo);
  192.             kind->PrivSetDirty(ev, FALSE, storageKind);
  193.         }
  194.     }
  195. }
  196.     
  197. //----------------------------------------------------------------------------------------
  198. //    FW_CContent::ExternalizeKind
  199. //----------------------------------------------------------------------------------------
  200.  
  201. void FW_CContent::ExternalizeKind(Environment* ev,
  202.                             ODStorageUnit* storageUnit,
  203.                             FW_CKind* kind,
  204.                             FW_StorageKinds storageKind,
  205.                             FW_CPromise* promise,
  206.                             FW_CCloneInfo* cloneInfo)
  207. {
  208. FW_UNUSED(ev);
  209. FW_UNUSED(storageUnit);
  210. FW_UNUSED(kind);
  211. FW_UNUSED(storageKind);
  212. FW_UNUSED(cloneInfo);
  213. FW_UNUSED(promise);
  214.  
  215.     FW_DEBUG_MESSAGE("You need to override FW_CContent::ExternalizeKind");
  216. }
  217.  
  218. //----------------------------------------------------------------------------------------
  219. //    FW_CContent::Internalize
  220. //----------------------------------------------------------------------------------------
  221. //    Override InternalizeKind
  222.  
  223. FW_Boolean FW_CContent::Internalize(Environment* ev,
  224.                                     ODStorageUnit* storageUnit, 
  225.                                     FW_StorageKinds storageKind,
  226.                                     FW_CCloneInfo* cloneInfo)
  227. {
  228.     FW_Boolean done = FALSE;
  229.     FW_Boolean result = FALSE;
  230.     
  231.     // ----- Look first for a file (part storage only) -----
  232. #ifdef FW_BUILD_MAC
  233.     if (storageKind == FW_kPartStorage)
  234.     {
  235.         HFSFlavor valueData;
  236.         if (FW_MacSUReadHFSFlavor(ev, storageUnit, kODPropContents, valueData))
  237.         {
  238.             FW_CPartKindIterator ite(fPart);
  239.             for (FW_CKind* kind = ite.First(); ite.IsNotComplete();  kind = ite.Next()) 
  240.             {
  241.                 if (kind->ImportSupported(ev, storageKind)) 
  242.                 {
  243.                     if (kind->IsEqual(ev, valueData.fileType, kODPlatformFileType)) 
  244.                     {
  245.                         storageUnit->Focus(ev, kODPropContents, kODPosUndefined, kind->GetType(ev), 0, kODPosUndefined);
  246.                         result = InternalizeKind(ev, storageUnit, kind, storageKind, cloneInfo);
  247.                         done = TRUE;
  248.                         break;
  249.                     }
  250.                 }
  251.             }
  252.         }
  253.     }
  254. #endif
  255.  
  256.     if (!done)
  257.     {
  258.         FW_CKind* theKind = NULL;
  259.         
  260.         // ----- if part storage use the preferred kind. For other storage use the highest supported fidelity
  261.         if (storageKind == FW_kPartStorage)
  262.         {
  263.             theKind = fPart->GetPreferredKind(ev);
  264.             FW_ASSERT(theKind != NULL);        // Otherwise why was I bound to this part?
  265.             FW_ASSERT(storageUnit->Exists(ev, kODPropContents, theKind->GetType(ev), 0)); // and it better exists
  266.         }
  267.         else
  268.             theKind = fPart->GetSupportedKind(ev, storageUnit, storageKind);
  269.         
  270.         if (theKind != NULL)
  271.         {
  272.             storageUnit->Focus(ev, kODPropContents, kODPosUndefined, theKind->GetType(ev), 0, kODPosUndefined);
  273.             result = InternalizeKind(ev, storageUnit, theKind, storageKind, cloneInfo);
  274.         }
  275.     }
  276.     
  277.     return result;
  278. }
  279.  
  280. //----------------------------------------------------------------------------------------
  281. //    FW_CContent::InternalizeKind
  282. //----------------------------------------------------------------------------------------
  283.  
  284. FW_Boolean FW_CContent::InternalizeKind(Environment* ev,
  285.                                     ODStorageUnit* storageUnit, 
  286.                                     FW_CKind* kind,
  287.                                     FW_StorageKinds storageKind,
  288.                                     FW_CCloneInfo* cloneInfo)
  289. {
  290. FW_UNUSED(ev);
  291. FW_UNUSED(storageUnit);
  292. FW_UNUSED(kind);
  293. FW_UNUSED(storageKind);
  294. FW_UNUSED(cloneInfo);
  295.     
  296.     FW_DEBUG_MESSAGE("You need to override FW_CContent::InternalizeKind");
  297.     return FALSE;
  298. }
  299.